package pl.edu.agh.gt.ga.greedy;

import org.apache.log4j.Logger;

import pl.edu.agh.gt.Stock;
import pl.edu.agh.gt.stock.Trader;

public class Validator {

	private final static Logger log = Logger.getLogger(Stock.class);

	public static Object validate(Object newVal, String name) {
		
		Object repaired = newVal;
		
		// greedB XXX
		if(name.equals("greedA") && (Float)newVal < 0.0) {
			repaired =  new Float(0.0);
		} else if(name.equals("maxLoss") && (Float)newVal > 0.0) {
			repaired =  new Float(0.0);
		} else if(name.equals("desiredEarn") && (Float)newVal < 0.0) {
			repaired =  new Float(0.0);
		} else if(name.equals("enteringValue") && (Float)newVal < 0.0) {
			repaired =  new Float(0.0);
		} else if(name.equals("enteringValue") && (Float)newVal > Trader.INITIAL_VALUE) {
			repaired =  new Float(Trader.INITIAL_VALUE);
		} else if(name.equals("lossTolerancy") && (Float)newVal < 0.0) {
			repaired =  new Float(0.0);
		}
		
//		if(repaired != newVal )
//			log.warn("Repairing gene '"+name+"' = "+newVal);
		
		return repaired;
	}
}
